Physically-based materials

This example demonstrates the use of physically-based shading and HDR post-processing in Kanzi. Since physically-based shading and HDR post-processing are still in the development phase, use these examples as a sneak peak into a technology you will be able to use in a later version of Kanzi.

Key features:

You can find the examples that show the use of physically-based materials in these example projects:

Limitations

Required OpenGL ES extensions

Advanced materials with post-processing requires either OpenGL ES 3.x, or OpenGL ES 2.0 with a set of extensions. The following OpenGL ES extensions are required when using OpenGL ES 2.0:

If these extensions are not available, it is still possible to use physically-based materials and lights, however, currently post-processing is not available without these extensions.

To use post-processing, set in the Project > Properties the Target Graphics API property to at least OpenGL ES 2.0 Extension Pack.

Overview of post-processing steps

Post-processing requires these main steps:

Setting up post-processing

To use post-processing you need to set up these resources:

  1. Resources. Resources, such as textures, composers, render passes, material types, shaders, materials, custom property types are needed from Post_Processing example project.

    You also need the "Prefabs/Quad Scene" prefab. This scene prefab contains only one, specially prepared object: a quad with extents from (-1, -1) to (1, 1). The quad has a tag "Quad" which is used in post-processing composers to specify object source for render passes that apply the post-processing effect to a texture. Do not modify this prefab.

    There are two versions of the example project. Post_Processing_Simple is nearly minimal setup, and Post_Processing has extra pages to show the scene with and without post processing, and to show intermediate textures.

    The example projects are prepared for target resolution of 1920x1080. The debug version of the example project has resources to support a few other resolutions.

  2. The main scene prefab template. The main scene must come from a prefab. In the example project this prefab is called "Prefabs/Main Scene". This is where you place content you want to render with post-processing.

    To support physically-based material shading, the scene prefab must have these properties:

    Additionally, the scene prefab template must have "Prefab preview mode" property set to 1. This value is intended to be overridden in the placeholders. This way, when previewing the prefab placeholder composition (value 1), material shaders perform additional tone mapping. Normally tone mapping is done after (or at the end of) post processing (value 0).

    For detailed descriptions of these properties, see Property Types.

  3. Host node for post-processing properties. The project must have an ancestor node that contains properties to control the post-processing effect. In the example project this node is a Page Host named "Page".
  4. Viewport for the "Scene to Texture". The node from the previous step ("Page") must contain a viewport for rendering scene to texture. In the Post_Processing_Simple example project this viewport is named "Page/Scene to Texture".

    The viewport must have the Layer Aspect Ratio property set to a value that matches the aspect ratio of the target resolution. In the example project the target resolution is 1920x1080 with aspect ratio of 1.777.

    The viewport should have an alias to provide an easy access to the Layer Aspect Ratio property. In the example project the resource dictionary of the "Screen" has the "Viewport" alias.

  5. Scene placeholder for the "Scene to Texture". The viewport from the previous step ("Page/Scene to Texture") must have a scene placeholder which instantiates the "Main Scene" prefab template from the step ("Prefabs/Main Scene"). In the example project this scene placeholder is named "Scene to Texture/Scene (Main Scene)".

    The scene placeholder must have the Composer property with value "Render to Texture (1920x1080) Composer".

    The scene placeholder must have the "Prefab Preview Mode" property set to 0. This directs the material shader to operate normally (without extra tone mapping).

    This node renders the contents of the main scene to the "HDR Render 1920x1080" render target texture, which is later used as input for post-processing operations.

  6. Providing access to the "Inverse Exposure" property. The Preview composition for the Main Scene prefab template requires the value of the exposure value for tone mapping. Because prefabs cannot access anything outside the prefab, this property is stored in the prefab, and made available to the project using the prefab placeholder.

    The scene placeholder from the previous step ("Scene (Main Scene)") must have an alias, to provide easy access to exposure property. In the example project, the resource dictionary of the Screen has the "MainScene" alias that points to the scene placeholder.

    The node from step 3 ("Page") must have this binding for the "Inverse Exposure" property:

    {#MainScene/Exposure}

    Post-processing nodes that need the exposure setting get it from the node from step 3 ("Page") through this binding and property inheritance.

  7. Viewport for "Post Processing Intermediate". The node from step 3 ("Page") must contain a viewport for the intermediate post-processing operation. In the example project, this viewport is called "Page/Post Processing Intermediate".
  8. Scene placeholder for "Post Processing Intermediate". The viewport from the previous step ("Page/Post Processing Intermediate") must contain a scene placeholder for the "Prefabs/Quad Scene" prefab (from step 1). In the example project, this is the "Post Processing Intermediate/Scene (Quad Scene)".

    The scene placeholder must have the Composer property set to "Post Processing (1920x1080) Intermediate Composer".

    The shaders that create the bloom in this composer need these properties to control the bloom effect:

    These are inheritable properties and they come from the node in step 3 ("Page").

    The viewport must have a binding for the Inverse Exposure property so that it uses value from the scene:

    - {Inverse Exposure} = {../Scene/Exposure}

    For detailed descriptions of these properties, see Property Types.

  9. Viewport for "Final Composition". The node from step 3 ("Page") must contain a viewport for the final composition. In the Post_Processing_Simple example project, this viewport is named "Page/Final Composition".
  10. Scene placeholder for "Final Composition". The viewport from step 9 ("Page/Final Composition") should contain a scene placeholder for "Prefabs/Quad Scene" prefab (from step 1). In the example project, this scene is named "Final Composition/Scene (Quad Scene)".

    The scene placeholder must have the Composer property set to "Post Processing (1920x1080) Final Composer".

    The shader that creates the bloom composition and tone mapping needs these properties:

    These are inheritable properties and they must come from the node in step 3 ("Page").

    For detailed descriptions of these properties, see Property Types.

Materials and Textures

Note that you must not modify these textures.

Composers

Property Types

Physically-based lights properties:

Post-processing (bloom effect and tone mapping) properties:

Environment properties:

Material properties:

Physically-based material types

All material types in this folder use identical shader sources for physically-based material. The material types are customized with Preprocessor Defines property. The main purpose of various preprocessor defines is to allow creation of optimized shader variants. In theory, it might be possible to use one, or only few, variants of the physically-based material type. In practice, it may be necessary to create more variants of physically-based material type to reach better performance.

To create a new variant, duplicate an existing material type, adjusted preprocessor defines to minimum of required features, and click Sync with Uniforms.

The shader uses the following preprocessor defines:

You can use these preprocessor defines for debugging. To enable debugging, set the values to 1:

These preprocessor defines are required, but they are used for features that are still in development. Always use value 0 for these:

Post-processing material types

See also

Examples